package ahpu.piconet.listener;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import ahpu.piconet.util.DataThread;

public class MyApplistener implements ServletContextListener  {

	private ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-persistent.xml");
	private final DataThread dt =ctx.getBean(DataThread.class);
	private Timer timer = null;
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.out.println("服务开启!向数据库中插入数据-------------");
		timer = new Timer(true);
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				System.out.println("插入一条数据-----");
				dt.run();
			}
		}, 0, 1000000);
	}
}
